﻿using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class pgSelect : Page
{
    #region Control Events

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (ValidateInformation())
        {
            Session.Add("Branding", ddlBrands.SelectedValue);

            Response.Redirect("~/Default.aspx");
        }
    }

    #endregion

    #region Functions

    protected override void OnInit(EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadBrands();
        }
    }

    private void LoadBrands()
    {
        ddlBrands.Items.Clear();
        ddlBrands.Items.Add(new ListItem("-- Select --"));

        string[] saBrands = Directory.GetDirectories(Server.MapPath("~/Branding/"));

        foreach (string sBrand in saBrands)
        {
            string sFormattedBrand = sBrand.Replace(Server.MapPath("~/Branding/"), "");

            ddlBrands.Items.Add(new ListItem(sFormattedBrand, sFormattedBrand));
        }

        ddlBrands.DataBind();
    }

    #endregion

    #region Validation

    private bool ValidateInformation()
    {
        bool valid = true;

        if (ddlBrands.SelectedValue.Contains("Select"))
        {
            valid = false;
        }

        return valid;
    }

    #endregion
}